<!--
Theme Name: Kelontong
Theme URI: http://www.icreativelabs.com/
Description: None.
Version: 1.0.0
Author: iCreative Labs
Author URI: http://www.icreativelabs.com
Tags: blue, black
	Kelontong v1.0.0
	http://www.icreativelabs.com/
	This theme was designed and built by None,
	whose blog you will find at http://www.icreativelabs.com/
	The CSS, XHTML and design is released under GPL:
	http://www.opensource.org/licenses/gpl-license.php
-->
<?php
global $icl_utility, $wpsc_query, $wpdb, $query_string, $current_product_id;

$query_string = '&'.$query_string;

$image_width = get_option('single_view_image_width');
$image_height = get_option('single_view_image_height');
?>
<?php while (wpsc_have_products()) :  wpsc_the_product(); ?>
<?php $current_product_id = wpsc_the_product_id(); ?>
<div id="product-details" class="block">
	<div class="product-text">
		<?php $product_permalink = wpsc_the_product_permalink(); ?>
		<h1 class="product-name">
			<?php if(get_option('hide_name_link') == 1) : ?>
				<span><?php echo wpsc_the_product_title(); ?></span>
			<?php else: ?> 
				<a href="<?php echo $product_permalink; ?>" title="<?php echo wpsc_the_product_title(); ?>"><?php echo wpsc_the_product_title(); ?></a>
			<?php endif; ?>
		</h1><!-- .product-name -->
		<div class="product-category">
		<?php
			echo $icl_utility->output_get_categories(wpsc_the_product_id(), ', ', '<a href="%s">', '</a>');
			$categories_name = $icl_utility->output_get_categories(wpsc_the_product_id(), ', ');
			$categories_id = $icl_utility->output_get_categories_id(wpsc_the_product_id(), ', ');
		?>
		</div><!-- .product-category -->
		<div class="product-price">
		<?php if(wpsc_product_is_donation()) : ?>
		<!--
		<label for='donation_price_<?php echo wpsc_the_product_id(); ?>'><strong><?php echo TXT_WPSC_DONATION; ?>:</strong></label>
		<input type='text' id='donation_price_<?php echo wpsc_the_product_id(); ?>' name='donation_price' value='<?php echo $wpsc_query->product['price']; ?>' size='6' />
		-->
		<?php else : ?>
			<?php if(wpsc_product_on_special()) : ?>
				<strong style="text-decoration:line-through;"><?php echo wpsc_product_normal_price(); ?></strong>
			<?php endif; ?>
			<strong><?php echo wpsc_the_product_price(); ?></strong>
			<br/>
			<?php if(wpsc_product_has_multicurrency()) : ?>
			<?php //echo wpsc_display_product_multicurrency(); ?>
			<?php endif; ?>
			<?php if(get_option('display_pnp') == 1) : ?>
			<span class="pricedisplay"><?php echo wpsc_product_postage_and_packaging(); ?></span><?php echo TXT_WPSC_PNP; ?>:  <br />
			<?php endif; ?>	
		<?php endif; ?>
		</div><!-- .product-price -->
		<div class="product-description">
			<p class="excerpt"><?php echo $wpsc_query->product['excerpt']; ?></p>
			<?php echo wpsc_the_product_description(); ?>
		</div><!-- .product-description -->
		
		<?php
		if((wpsc_product_has_file() == true)  && (function_exists('listen_button'))){
			$file_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `id`='".$wpsc_query->product['file']."' LIMIT 1",ARRAY_A);
			if($file_data != null) {
				echo listen_button($file_data['idhash'], $file_data['id']);
			}
		}
		?>
		<div class="addtocart">
			<form class="product_form" enctype="multipart/form-data" action="<?php echo wpsc_this_page_url(); ?>" method="post" name="1" id="product_<?php echo wpsc_the_product_id(); ?>" name="product_<?php echo wpsc_the_product_id(); ?>">
				<?php if(wpsc_product_has_personal_text()) : ?>
					<br clear="all"/>
					<div class='custom_text'>
						<strong><?php echo TXT_WPSC_PERSONALIZE_YOUR_PRODUCT; ?></strong><br />
						<?php echo TXT_WPSC_PERSONALIZE_YOUR_PRODUCT_DESCRIPTION; ?><br />
						<textarea name='custom_text' rows='5' style="width:100%;"></textarea>
					</div>
				<?php endif; ?>

				<?php if(wpsc_product_has_supplied_file()) : ?>
					<br clear="all"/>
					<div class='custom_file'>
						<strong><?php echo TXT_WPSC_UPLOAD_A_FILE; ?></strong><br />
						<?php echo TXT_WPSC_UPLOAD_A_FILE_DESCRIPTION; ?><br />
						<input type='file' name='custom_file' value='' />
					</div>
				<?php endif; ?>

				<?php /** the variation group HTML and loop */?>
				<div class="wpsc_variation_forms">
					<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
						<br clear="all"/>
						<p>
							<label for="<?php echo wpsc_vargrp_form_id(); ?>"><strong><?php echo wpsc_the_vargrp_name(); ?>:</strong></label>
							<?php /** the variation HTML and loop */?>
							<select class='wpsc_select_variation' name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
							<?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
								<option value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?>><?php echo wpsc_the_variation_name(); ?></option>
							<?php endwhile; ?>
							</select> 
						</p>
					<?php endwhile; ?>
				</div>
				<?php /** the variation group HTML and loop ends here */?>

				<!-- THIS IS THE QUANTITY OPTION MUST BE ENABLED FROM ADMIN SETTINGS -->
				<?php if(wpsc_has_multi_adding()): ?>
					<br clear="all"/>
					<label class='wpsc_quantity_update' for='wpsc_quantity_update'><strong><?php echo TXT_WPSC_QUANTITY; ?>:</strong></label>
					<input type="text" id='wpsc_quantity_update' name="wpsc_quantity_update" size="2" value="1"/>
					<input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
					<input type="hidden" name="wpsc_update_quantity" value="true"/>
				<?php endif ;?>
				<!-- END OF QUANTITY OPTION -->

				<?php
					if(function_exists('wpsc_akst_share_link') && (get_option('wpsc_share_this') == 1))
					{
						echo wpsc_akst_share_link('return');
					} 
				?>

				<input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
				<input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>

				<?php if(wpsc_product_is_customisable()) : ?>				
					<input type="hidden" value="true" name="is_customisable"/>
				<?php endif; ?>
				
				<?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow') !='1')) : ?>
					<?php if(wpsc_product_has_stock()) : ?>
					<?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
						<?php $action =  wpsc_product_external_link(wpsc_the_product_id()); ?>
					<a href="#" onclick="javascript:gotoexternallink('<?php echo $action; ?>');"><?php echo TXT_WPSC_BUYNOW; ?></a>
					<?php else: ?>
					<a href="javascript:;" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button" onclick="javascript:jQuery('#product_<?php echo wpsc_the_product_id(); ?>').submit();"><?php echo TXT_WPSC_ADDTOCART; ?></a>
					<?php endif; ?>
					<div class='wpsc_loading_animation'>
						<img title="Loading" alt="Loading" src="<?php echo WPSC_URL ;?>/images/indicator.gif" class="loadingimage" />
						<?php echo TXT_WPSC_UPDATING_CART; ?>
					</div>
					<?php else : ?>
					<p class='soldout'><?php echo TXT_WPSC_PRODUCTSOLDOUT; ?></p>
					<?php endif ; ?>
				<?php endif ; ?>
				
				<?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow')=='1')) : ?>
					<?php echo wpsc_buy_now_button(wpsc_the_product_id()); ?>
				<?php endif; ?>
			</form>
		</div><!-- .addtocart -->
		
		<?php echo wpsc_product_rater(); ?>
		
		<form onsubmit="submitform(this);return false;" action="<?php echo wpsc_this_page_url(); ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_extra_<?php echo wpsc_the_product_id(); ?>">
			<input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="prodid"/>
			<input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="item"/>
		</form>
	</div><!-- .product-text -->
	<div class="product-image">
		<?php $product_picture = get_product_meta(wpsc_the_product_id(), 'product_picture'); ?>
		<?php if($product_picture != '') : ?>
		<div class="main-image">
			<img alt="<?php echo wpsc_the_product_title(); ?>" src="<?php echo $product_picture; ?>" />
		</div><!-- .main-image -->
		<?php endif; ?>
	</div><!-- .product-image -->
	<div class="clear"></div>
	<a class="link_full_specification" href="javascript:;"><?php _e('View Full Specifications'); ?></a>
	<div id="full_specification" style="display:none;">
		<div class="product-additional-description">
			<?php do_action('wpsc_product_addons', wpsc_the_product_id()); ?>
			<?php if(wpsc_the_product_additional_description()) : ?>
			<?php
				$value = '';
				$the_addl_desc = wpsc_the_product_additional_description();
				if( is_serialized($the_addl_desc) ) {
					$addl_descriptions = @unserialize($the_addl_desc);
				} else {
					$addl_descriptions = array('addl_desc', $the_addl_desc);
				}
				
				if( isset($addl_descriptions['addl_desc']) ) {
					$value = $addl_descriptions['addl_desc'];
				}

				if( function_exists('wpsc_addl_desc_show') ) {
					echo wpsc_addl_desc_show( $addl_descriptions );
				} else {
					echo $the_addl_desc;
				}
			?>
			<?php endif; ?>
			<?php do_action('wpsc_product_addon_after_descr', wpsc_the_product_id()); ?>
			<?php // show custom meta ?>
			<?php if (wpsc_have_custom_meta()) : ?>
			<?php if ($the_addl_desc != '') : ?>
			<br/><br/>
			<?php endif; ?>
			<div class="custom_meta">
				<?php while (wpsc_have_custom_meta()) : wpsc_the_custom_meta(); ?>
					<?php if (wpsc_custom_meta_name() != 'product_picture') : ?>
					<strong><?php echo wpsc_custom_meta_name(); ?>: </strong><?php echo wpsc_custom_meta_value(); ?><br />
					<?php endif; ?>
				<?php endwhile; ?>
			</div><!-- .custom-meta -->
			<?php endif; ?>
		</div><!-- .product-additional-description -->
	</div><!-- #full_specification -->
	<div class="clear"></div>
	<?php echo wpsc_product_comments(); ?>
</div><!-- #product-details -->
<?php endwhile; ?>
<?php
	if(function_exists('fancy_notifications'))
	{
		echo fancy_notifications();
	}
?>
<div class="clear"></div>
<?php
	$page = $icl_utility->stripNonText($_GET['page']);
	$current_page = (isset($page) && $page != '') ? $page : 1;
	$i_row = 1;
	$i_product = 1;
	$max_per_row = 3;
	$max_per_page = 12;

	$sql = 'SELECT ' . WPSC_TABLE_PRODUCT_LIST . '.id, name, LEFT(description, 80) as description, image, price, special_price, donation ';
	$sql .= 'FROM ' . WPSC_TABLE_PRODUCT_LIST . ' LEFT JOIN ' . WPSC_TABLE_ITEM_CATEGORY_ASSOC . ' ON ';
	$sql .= WPSC_TABLE_PRODUCT_LIST . '.id = ' . WPSC_TABLE_ITEM_CATEGORY_ASSOC . '.product_id ';
	$sql .= 'WHERE publish = 1 AND active = 1 AND ' . WPSC_TABLE_ITEM_CATEGORY_ASSOC . '.category_id IN (' . $categories_id . ') ';
	if ($current_product_id != '')
	{
		$sql .= 'AND ' . WPSC_TABLE_PRODUCT_LIST . '.id != ' . $current_product_id . ' ';
	}

	$product_count = count($wpdb->get_results($sql, ARRAY_A));

	$sql .= ' GROUP BY ' . WPSC_TABLE_PRODUCT_LIST . '.id LIMIT ' . (($current_page - 1) * $max_per_page) . ', ' . $max_per_page;

	$wpsc_query->products = $wpdb->get_results($sql, ARRAY_A);
	$wpsc_query->product_count = count($wpsc_query->products);

	$max_page = ceil($product_count / $max_per_page);
	$max_page = ($max_page == 0) ? 1 : $max_page;
?>
<div id="others" class="product-listing-top">
	<h3><?php _e('Related Products'); ?></h3>
	<div class="listing-top-right">
		<p><?php _e('Page'); ?> <?php echo $current_page ?> <?php _e('of'); ?> <?php echo $max_page ?></p>
		<p>
			<?php if ($current_page == 1) : ?>
			<label>< <?php _e('Previous'); ?></label>
			<?php else: ?>
			<a href="<?php echo $product_permalink; ?>?page=<?php echo ($current_page - 1); ?>#others">< <?php _e('Previous'); ?></a>
			<?php endif; ?>
			|
			<?php if ($current_page == $max_page) : ?>
			<label><?php _e('Next'); ?> ></label>
			<?php else: ?>
			<a href="<?php echo $product_permalink; ?>?page=<?php echo ($current_page + 1); ?>#others"><?php _e('Next'); ?> ></a>
			<?php endif; ?>
		</p>
	</div><!-- .listing-top-right -->
	<div class="clear"></div>
</div><!-- .product-listing-top -->
<ul class="product-listing">
	<li class="clear"></li>
<?php while (wpsc_have_products()) :  wpsc_the_product(); ?>
	<li class="product-li">
		<div class="list-image">
		<?php if(get_option('show_thumbnails')) :?>
		<?php $product_image = wpsc_the_product_image(); ?>
		<?php if($product_image != '') :?>
			<a href="<?php echo wpsc_the_product_permalink(); ?>">
				<img id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php bloginfo('stylesheet_directory'); ?>/libraries/timthumb.php?w=145&src=<?php echo urlencode($product_image); ?>" />
			</a>
		<?php else: ?>
			<span>No Image Available</span>
		<?php endif; ?>
		<?php endif; ?>
		</div><!-- .list-image -->
		<div class="list-desc">
			<h5>
				<?php if(get_option('hide_name_link') == 1) : ?>
					<span><?php echo wpsc_the_product_title(); ?></span>
				<?php else: ?> 
					<a href="<?php echo wpsc_the_product_permalink(); ?>"><?php echo wpsc_the_product_title(); ?></a>
				<?php endif; ?>
			</h5>
			<p class="list-category">
				<?php echo $icl_utility->output_get_categories(wpsc_the_product_id(), ', ', '<a href="%s">', '</a>'); ?>
			</p><!-- .list-category -->
			<p class="list-price">
				<?php if(wpsc_product_is_donation()) : ?>
				<?php else : ?>
					<?php if(wpsc_product_on_special()) : ?>
						<span style="text-decoration:line-through;"><?php echo wpsc_product_normal_price(); ?></span>
					<?php endif; ?>
					<?php echo wpsc_the_product_price(); ?>
				<?php endif; ?>
			</p><!-- .list-price -->
			<p class="list-description">
				<?php echo wpsc_the_product_description(); ?>
			</p><!-- .list-description -->
			<div class="more">
				<a href="<?php echo wpsc_the_product_permalink(); ?>"><?php _e('More Information'); ?></a>
			</div><!-- .more -->
		</div><!-- .list-desc -->
	</li><!-- .product-li -->
<?php endwhile; ?>
	<li class="clear"></li>
</ul><!-- .product-listing -->
<div class="product-listing-bottom">
	<div class="listing-bottom-right">
		<p><?php _e('Page'); ?> <?php echo $current_page ?> <?php _e('of'); ?> <?php echo $max_page ?></p>
		<p>
			<?php if ($current_page == 1) : ?>
			<label>< <?php _e('Previous'); ?></label>
			<?php else: ?>
			<a href="<?php echo $product_permalink; ?>?page=<?php echo ($current_page - 1); ?>#others">< <?php _e('Previous'); ?></a>
			<?php endif; ?>
			|
			<?php if ($current_page == $max_page) : ?>
			<label><?php _e('Next'); ?> ></label>
			<?php else: ?>
			<a href="<?php echo $product_permalink; ?>?page=<?php echo ($current_page + 1); ?>#others"><?php _e('Next'); ?> ></a>
			<?php endif; ?>
		</p>
	</div><!-- .listing-bottom-right -->
	<div class="clear"></div>
</div><!-- .product-listing-bottom -->